{include file="public_head" /}

<!-- Select2 -->
<link href="__STATIC__/css/select/select2.min.css" rel="stylesheet">
<!-- upload -->
<link href="__STATIC__/css/uploads.css" rel="stylesheet">
<!-- upload_arr -->
<link href="__STATIC__/plupload/plupload.css" rel="stylesheet">
<body class="nav-md">

<div class="container body">

    <div class="main_container">

        {include file="public_sidebar,public_nav" /}
        <!-- page content -->
        <div class="right_col" role="main">
            <div class="">

                <div class="page-title">
                    <div class="title_left">
                        <h3>会员卡管理</h3>
                    </div>
                </div>
                <div class="clearfix"></div>
                <div class="row">
                    <div class="col-md-12 col-sm-12 col-xs-12">
                        <div class="x_panel">
                            <div class="x_title">
                                <h2>{$mate_title}
                                </h2>
                                <ul class="nav navbar-right panel_toolbox">
                                    <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                                    </li>
                                    <li><a class="close-link"><i class="fa fa-close"></i></a>
                                    </li>
                                </ul>
                                <div class="clearfix"></div>
                            </div>
                            <div class="x_content">
                                <div class="printArea">
                                <br/>
                                <form class="form-horizontal form-label-left" enctype="multipart/form-data" action=""
                                      method="post" id="registerForm" >
                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">会员卡类型：</label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <label class="radio_box">
                                                <input type="radio" name="type" id="status_122" class="cartradio"
                                                       value="1"
                                                       datatype="*"
                                                       nullmsg="请选择会员卡类型！" errormsg="请选择会员卡类型！"
                                                       {eq name='item.type|default="1"' value='1' }
                                                       checked
                                                       {/eq}
                                                >&nbsp;&nbsp;
                                                <label for="status_122"></label>
                                                <span>年卡</span>
                                                &nbsp;&nbsp;
                                            </label>
                                            <label class="radio_box">
                                                <input type="radio" name="type" id="status_222" class="cartradio"
                                                       value="2"
                                                       datatype="*"
                                                       nullmsg="请选择会员卡类型！" errormsg="请选择会员卡类型！"
                                                       {eq name='item.type|default=""' value='2' }
                                                       checked
                                                       {/eq}
                                                >&nbsp;&nbsp;
                                                <label for="status_222"></label>
                                                <span>次卡</span>
                                                &nbsp;&nbsp;
                                            </label>
                                        </div>
                                    </div>
                                    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
                                    <script>

                                        $('#status_122').click(function(){
                                            $('#in').html('');
                                        });
                                        $('#status_222').click(function(){
                                            $('#in').html('<div class="form-group">\n' +
                                                '                                            <label class="control-label col-md-3 col-sm-3 col-xs-12">使用次数：</label>\n' +
                                                '                                            <div class="col-md-2 col-sm-6 col-xs-12">\n' +
                                                '                                                <input type="text" placeholder="请输入使用次数"\n' +
                                                '                                                       class="form-control col-md-7 col-xs-12" name="count"\n' +
                                                '                                                       value="{$item.count|default=\'\'}"\n' +
                                                '                                                       datatype="*"\n' +
                                                '                                                       nullmsg="请输入月卡次数！" errormsg="请输入使用次数"\n' +
                                                '                                                >\n' +
                                                '                                            </div>\n' +
                                                '                                        </div>');
                                            $('#in').html('');
                                        });

//                                        window.onload = function () {
//                                            $('#status_2').trigger('click');
//                                        };
                                        {if condition="request()->action() eq 'update' && $item.type eq 2"}
                                        $(function () {
                                            $('#status_222').trigger('click');
                                        });
                                        {/if}

                                    </script>
                                    <!--<div class="form-group">-->
                                        <!--<label class="control-label col-md-3 col-sm-3 col-xs-12">指派人：</label>-->
                                        <!--<div class="col-md-6 col-sm-6 col-xs-12">-->
                                            <!--<select name="shop_assignor_id[]" class="select2_multiple form-control"-->
                                                    <!--multiple="multiple"-->
                                                    <!--style="width: 500px;" tabindex="-1"-->
                                                    <!--datatype="*"-->
                                                    <!--nullmsg="请选择指派人！" errormsg="请选择指派人！"-->
                                            <!--&gt;-->
                                                <!--<option value="0"-->
                                                <!--&gt;-->
                                                    <!--请选择指派人-->
                                                <!--</option>-->
                                                <!--{volist name=":db('member')->select()" id="list"}-->
                                                <!--<option-->

                                                        <!--{in name='list.id' value='$item.shop_assignor_id|default=""'}selected{/in}-->
                                                <!--value="{$list.id}"-->
                                                <!--&gt;-->

                                                <!--{$list.username}-->
                                                <!--</option>-->
                                                <!--{/volist}-->

                                            <!--</select>-->
                                        <!--</div>-->
                                    <!--</div>-->


                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">会员卡标题：</label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input type="text" placeholder="请输入会员卡标题"
                                                   class="form-control col-md-7 col-xs-12" name="title"
                                                   value="{$item.title|default=''}"
                                                   datatype="*"
                                                   nullmsg="请输入会员卡标题！" errormsg="请输入会员卡标题！"
                                            >
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">图片上传【720*372】:</label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <div id="imgdiv">
                                                <img id="imgShow" src="__PUBLIC__/{$item.single_pic|default=''}"
                                                     width="200" height="190" onerror="this.src='__STATIC__/images/default.png'"
                                                />
                                            </div>
                                            <div class="uploader white">
                                                <input type="text" class="filename" name="single_pic"
                                                       value="{$item.single_pic|default=''}" readonly/>
                                                <input type="button" name="file" class="button" value="上传..."/>
                                                <input type="file" id="up_img" name="single_pic"
                                                       value='{$item.single_pic|default=""}'  />
                                            </div>
                                        </div>
                                    </div>
                                    <div id="in">

                                    </div>


                                    <!--<div class="form-group">-->
                                        <!--<label class="control-label col-md-3 col-sm-3 col-xs-12">派发数量：</label>-->
                                        <!--<div class="col-md-2 col-sm-6 col-xs-12">-->
                                            <!--<input type="text" placeholder="请填写派发数量"-->
                                                   <!--class="form-control col-md-7 col-xs-12" name="number"-->
                                                   <!--value="{$item.number|default=''}"-->
                                                   <!--datatype="int" id="num"-->
                                                   <!--nullmsg="请填写派发数量！" errormsg="请填写派发数量大于1的数字！"-->
                                            <!--&gt;-->
                                        <!--</div>-->
                                    <!--</div>-->

                                    <!--<div class="form-group">-->
                                        <!--<label class="control-label col-md-3 col-sm-3 col-xs-12">使用区间时间：</label>-->
                                        <!--<div class="col-md-6 col-sm-6 col-xs-12">-->
                                            <!--<input type="text" placeholder="请选择时间区间"-->
                                                   <!--class="form-control col-md-7 col-xs-12" name="interval_timer"-->
                                                   <!--id="interval_timer"-->
                                                   <!--{present name="$item.id"}-->
                                                   <!--value="{$item.start_time} / {$item.end_time}"-->
                                                   <!--{/present}-->
                                                   <!--datatype="*"-->
                                                   <!--nullmsg="请选择时间区间！" errormsg="请选择时间区间2！"-->
                                            <!--&gt;-->
                                        <!--</div>-->
                                    <!--</div>-->
                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">售价：</label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input type="text" placeholder="请输入会员卡金额"
                                                   class="form-control col-md-7 col-xs-12" name="sale_price"
                                                   value="{$item.sale_price|default=''}"
                                                   datatype="*"
                                                   nullmsg="请输入会员卡金额！" errormsg="请输入会员卡金额！"
                                            >
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">原价：</label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input type="text" placeholder="请输入会员卡金额"
                                                   class="form-control col-md-7 col-xs-12" name="origin_price"
                                                   value="{$item.origin_price|default=''}"
                                                   datatype="*"
                                                   nullmsg="请输入会员卡金额！" errormsg="请输入会员卡金额！"
                                            >
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">会员卡有效时限：</label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input type="text" placeholder="系统会员卡有效时限"
                                                   class="form-control col-md-7 col-xs-12" name="day"
                                                   value="{$item.day|default=''}"
                                                   datatype="n"
                                                   nullmsg="请输入系统会员卡有效时限！" errormsg="请输入系统会员卡有效时限！"
                                            >
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">添加数量：</label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input type="text" placeholder="请输入添加数量"
                                                   class="form-control col-md-7 col-xs-12" name="sycss"
                                                   value="{$item.sycss|default=''}"
                                                   datatype="*"
                                                   nullmsg="请输入添加数量！" errormsg="请输入添加数量！"
                                            >
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">会员卡服务类次数：</label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <table class="table table-striped table-bordered table-hover">
                                                <thead>
                                                <th>服务分类</th>
                                                <th>服务内容</th>
                                                <th>服务次数</th>
                                                {if condition="session('role_id') eq 11 || session('role_id') eq 12 || session('role_id') eq 13" }
                                                {else/}
                                                <th>操作</th>
                                                {/if}
                                                </thead>
                                                <tbody id="fieldtr">
                                                {volist name="gift_count" id="list"}
                                                <tr>
                                                    <td>
                                                        <select name="single_id[]" onchange="cate(this.value,this)" class="form-control" tabindex="-1">
                                                            {volist name=":json_decode($single_list,true)" id="li"}
                                                            <option value="{$li.id}" {eq name="$li.id" value="$list.single_id"}selected{/eq}>{:str_repeat('&nbsp',$li.level)}|-{$li.cat_name}</option>
                                                            {/volist}
                                                        </select>
                                                    </td>
                                                    <td>
                                                        <select name="single_content[]" class="form-control" tabindex="-1">
                                                            {volist name="list.two_array" id="li"}
                                                            <option value="{$li.id}" {eq name="$li.id" value="$list.single_content"}selected{/eq}>|-{$li.cat_name}</option>
                                                            {/volist}
                                                        </select>
                                                    </td>
                                                    <td><input type="text" name="gift_count[]" style="width:100px;" value="{$list.gift_count}"/></td>
                                                    {if condition="session('role_id') eq 11 || session('role_id') eq 12 || session('role_id') eq 13" }
                                                    {else/}
                                                    <td><a href="javascript:;" onclick="delThis($(this),{$list.id})" >删除</a></td>
                                                    {/if}
                                                </tr>
                                                {/volist}
                                                </tbody>
                                                {if condition="session('role_id') eq 11 || session('role_id') eq 12 || session('role_id') eq 13" }
                                                {else/}
                                                <tbody align="right">
                                                <tr>
                                                    <td colspan="5"><a href="javascript:;" class="addNewTr" title="新增一条" >新增一条</a></td>
                                                </tr>
                                                {/if}
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">会员卡内容：</label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <textarea type="text/plain" style=" height: 300px; width: 100%" id="containers"
                                                      name="content"
                                                      placeholder="请输入商品内容">
                                                {$item.content|default=''}
                                            </textarea>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">购买须知：</label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <textarea type="text/plain" style=" height: 300px; width: 100%" id="containers11"
                                                      name="buy_must_know"
                                                      placeholder="请输入商品内容">
                                                {$item.buy_must_know|default=''}
                                            </textarea>
                                        </div>
                                    </div>
                                    {include file="auding_status" /}
                                </div>


                                    <div class="form-group">
                                        <div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
                                            {present name="$item.id"}
                                            <input type="hidden" name="id" value="{$item.id}">
                                            {/present}
                                            <!--<input type="hidden" name="member_id" value="0"/>-->
                                            <button type="submit" class="btn btn-primary">提交</button>
                                            <a type="reset" class="btn btn-success" onclick="history.go(-1)">返回</a>

                                        </div>
                                    </div>

                                </form>
                            </div>
                        </div>
                    </div>
                </div>


            </div>
            <!-- /page content -->

        </div>

    </div>
</div>

{include file="public_foot" /}
<!-- validform -->
<script src="__STATIC__/js/Validform_v5.3.2_min.js"></script>
<script src="__STATIC__/js/layer.js"></script>
<!-- daterangepicker -->
<script src="__STATIC__/js/datepicker/daterangepicker.js"></script>
<!--select-->
<script src="__STATIC__/js/select/select2.full.min.js"></script>
<!-- upload -->
<script type="text/javascript" src="__STATIC__/js/uploadPreview.js"></script>
<!-- ueditor -->
<script type="text/javascript" charset="utf-8" src="__STATIC__/editor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__STATIC__/editor/ueditor.all.min.js"></script>
<script type="text/javascript" charset="utf-8" src="__STATIC__/editor/lang/zh-cn/zh-cn.js"></script>
<script>

    function ef(){
       var num = $("#num").val();

       if(num <= 1){

           layer.msg("派发数量必须大于1");
           return false;
       }

    }
    // validform
    $(function () {
        new uploadPreview({UpBtn: "up_img", DivShow: "imgdiv", ImgShow: "imgShow"});
        var ue = UE.getEditor('containers');
        var ue = UE.getEditor('containers11');
        $(".select2_single").select2({
            placeholder: "请选择分类",
            allowClear: true
        });

        $.Tipmsg.r = null;
        $.Datatype.int = /^[1-9]\d*$/;
        var showmsg = function (msg) {
            //假定你的店铺商品提示方法为showmsg， 在方法里可以接收参数msg，当然也可以接收到o及cssctl;
            alert(msg);
        }
        $("#registerForm").Validform({
            tiptype: function (msg) {
                layer.msg(msg);
            },
            tipSweep: true,

        });

        // interval_timer
        $('#interval_timer').daterangepicker(null,
                function(start, end, label) {
                    console.log(start.toISOString(), end.toISOString(), label);
                });

        // select2
        $(".select2_multiple").select2({
            maximumSelectionLength: 0,
            placeholder: "请选择关联栏目",
            allowClear: true
        });




        var single_list = {$single_list};
        var default_cotent = {$default_content};
        console.log(default_cotent);
        var ss = [];

        //var disabled = "disabled";
        $.each(single_list, function(k,v){
            var ds;
            if(v.level == 444){
                ds = 'disabled="disabled"';
            }else{
                ds = '';
            }
            ss += '<option value="'+v.id+'"'+ds+'>'+'&nbsp&nbsp'.repeat(v.level)+'|-'+v.cat_name+'</option>';
        });
        var sss = [];
        $.each(default_cotent, function(k,v){
            var ds;
            if(v.level == 444){
                ds = 'disabled="disabled"';
            }else{
                ds = '';
            }
            sss += '<option value="'+v.id+'"'+ds+'>'+'|-'+v.cat_name+'</option>';
        });

        $(".addNewTr").click(function(){
            str = '<tr><td><select name="single_id[]" onchange="cate(this.value,this)" class="form-control" tabindex="-1">' + ss +
                '</select></td>' +
                '<td><select name="single_content[]" class="form-control" tabindex="-1">' + sss +
                '</select></td>' +
                '<td><input type="text" name="gift_count[]" style="width:100px;" /></td>' +
                '<td><a href="javascript:;" onclick="delThisTr($(this))">删除</a></td></tr>';
            $("#fieldtr").append(str);
        });


    })
    function cate(vv,t) {
        $.ajax({
            url : '{:url("gift/single2")}',
            data:{'id':vv},
            dataType:'html',
            success:function(data){
                var data = JSON.parse(data);
                var s2;
                $.each(data, function(k,v){
                    s2 += '<option value="'+v.id+'">'+'|-'+v.cat_name+'</option>';
                });
                console.log(s2);
                var str = '<select name="single_content[]" class="form-control" tabindex="-1">'+ s2
                    +
                    '</select>';

                $(t).parent().next().html(str);
            }
        });
    }
    function delThisTr(trobj)
    {
        trobj.parent().parent().remove();
    }
    function delThis(trobj,id)
    {
        if(confirm('确认删除？')){
            $.ajax({
                url : '{:url("gift_count")}',
                data:{'id':id},
                dataType:'html',
                success:function(data){
                    if(data == 'true'){
                        layer.msg('删除成功');
                        trobj.parent().parent().remove();
                    }else{
                        layer.msg('网络繁忙,请重试');
                    }
                }
            });
        }
    }
</script>
<script src="/jquery.PrintArea.js" type="text/JavaScript" language="javascript"></script>

</body>

</html>
